package com.example.hospitalmanagement.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.example.hospitalmanagement.R
import com.example.hospitalmanagement.bean.ExpertIntroductionData
import de.hdodenhof.circleimageview.CircleImageView

class ExpertIntroductionActivityAdapter(context: Context) :
    RecyclerView.Adapter<ExpertIntroductionActivityAdapter.DoctorHolder>() {
    private val context = context
    lateinit var dataList: MutableList<ExpertIntroductionData>
    private lateinit var listener: (position: Int) -> Unit
    fun setListener(listener: (position: Int) -> Unit) {
        this.listener = listener
    }

    class DoctorHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val doctorPicture: CircleImageView = itemView.findViewById(R.id.doctor_picture)
        val doctorName: TextView = itemView.findViewById(R.id.doctor_name)
        val doctorDepartment: TextView = itemView.findViewById(R.id.doctor_department)
        val doctorAdept: TextView = itemView.findViewById(R.id.doctor_adept)
        val doctorGrade: TextView = itemView.findViewById(R.id.doctor_grade)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DoctorHolder {
        val doctorHolder = DoctorHolder(
            LayoutInflater.from(context).inflate(R.layout.expert_information_items, parent, false)
        )
        doctorHolder.itemView.setOnClickListener {
            listener(doctorHolder.adapterPosition)
        }
        return doctorHolder
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: DoctorHolder, position: Int) {
        holder.doctorAdept.text = "擅长:${dataList[position].docIntro}"
        holder.doctorDepartment.text = dataList[position].deskName
        holder.doctorName.text = dataList[position].docName
        holder.doctorGrade.text = when(dataList[position].docJob){
            1->"主任医师"
            2->"副主任医师"
            3->"主治医师"
            else->"实习医生"
        }
        Glide.with(context).load(dataList[position].docImg).into(holder.doctorPicture)
    }


    override fun getItemCount(): Int {
        return dataList.size
    }
}